package org.evolver.disser;

import javax.swing.*;
import net.miginfocom.swing.MigLayout;

public class InputPanel extends JPanel {
    /* Field declarations */
    private DoubleParameter     wg_b0;
    private DoubleParameter     wg_a0;
    private DoubleParameter     wg_alpha;
    private DoubleParameter     wg_q;

    private DoubleParameter     sm_b0;
    private DoubleParameter     sm_d0;
    private DoubleParameter     sm_alpha;

    private DoubleParameter     lambda;
    private DoubleParameter     t;
    private DoubleParameter     delta_l;
    private DoubleParameter     delta_xt;

    private DoubleParameter     epsMin;
    private DoubleParameter     epsMax;
    private IntegerParameter    precision;

    /* Default constructor */
    InputPanel() {
        MigLayout inputLayout = new MigLayout("", "[left][left][left]");
        setLayout(inputLayout);

        add(new JLabel("Параметры волновода"), "left, span, gaptop 10");
        wg_a0 = new DoubleParameter("Ширина", "мм", 32.0);
        wg_a0.addToPanel(this);
        wg_b0 = new DoubleParameter("Высота", "мм", 10.0);
        wg_b0.addToPanel(this);
        wg_alpha = new DoubleParameter("ЛКТР", "1/град", 10.0);
        wg_alpha.addToPanel(this);
        wg_q = new DoubleParameter("Коэфф. затухания", "", 0.000001);
        wg_q.addToPanel(this);

        add(new JLabel("Параметры образца"), "left, span, gaptop 10");
        sm_b0 = new DoubleParameter("Высота", "мм", 10.0);
        sm_b0.addToPanel(this);
        sm_d0 = new DoubleParameter("Глубина", "мм", 54.0);
        sm_d0.addToPanel(this);
        sm_alpha = new DoubleParameter("ЛКТР", "1/град", 10.0);
        sm_alpha.addToPanel(this);

        add(new JLabel("Параметры эксперимента"), "left, span, gaptop 10");
        lambda = new DoubleParameter("Длина волны ген.", "мм", 30.0);
        lambda.addToPanel(this);
        t = new DoubleParameter("Температура", "град. C", 10.0);
        t.addToPanel(this);
        delta_l = new DoubleParameter("Сдвиг минимума", "мм", 5.0);
        delta_l.addToPanel(this);
        delta_xt = new DoubleParameter("Ширина дв. минимума", "мм", 2.0);
        delta_xt.addToPanel(this);

        add(new JLabel("Параметры расчета"), "left, span, gaptop 10");
        epsMin = new DoubleParameter("Мин. epsilon", "", 1.0);
        epsMin.addToPanel(this);
        epsMax = new DoubleParameter("Макс. epsilon", "", 100.0);
        epsMax.addToPanel(this);
        precision = new IntegerParameter("Точность расчета", "знаков", 4);
        precision.addToPanel(this);
    }

    public InputData buildInputData() {
        return new InputData
                        (
                        lambda.getValue(),
                        wg_a0.getValue(),
                        wg_b0.getValue(),
                        sm_b0.getValue(),
                        sm_d0.getValue(),
                        wg_alpha.getValue(),
                        sm_alpha.getValue(),
                        t.getValue(),
                        delta_l.getValue(),
                        delta_xt.getValue(),
                        wg_q.getValue(),
                        epsMin.getValue(),
                        epsMax.getValue(),
                        precision.getValue()
                        );
    }
}
